export function getUrlParams(){
  let result = {}
  let queryString = window.location.search // 拿到url参数
  let reg = /[?&][^?&]+=[^?&]+/g
  let newSearch = queryString.match(reg)
  if(newSearch){
    newSearch.forEach(item=>{
     let temp = item.substring(1).split('=')
     let key = temp[0]
     let value = temp[1]
     result[key] = value
    })
  }
  return result
} 
function getIslandData() {
  const url = serverUrl + "wfs"
  let params = {
    srs: "EPSG:4326",
    ns: "http://localhost/pg",
    workspace: "pg",
    layers: ["pg:islands"],
  }
  get_WFSFeature(url, params).then((json) => {
    
  })
}

/**
 * WFS服务查询
 */
async function get_WFSFeature(url, options) {
  let params = {
    //坐标系
    srsName: options.srs || "EPSG:4326",
    //命名空间 URI(可以不传)
    featureNS: options.ns,
    //工作区名称
    featurePrefix: options.workspace,
    //查询图层，可以是同一个工作区下多个图层，逗号隔开
    featureTypes: options.layers,
    // 输出格式
    outputFormat: "application/json",
    //过滤条件，前者是属性名，后者是对应值
    // filter: andFilter(
    //   // likeFilter("name", "Mississippi*"),
    //   // equalToFilter("smz", "昂素镇")
    // )
  }
  if (options.filter) {
    params.filter = options.filter
  }
  let featureRequest = new WFS().writeGetFeature(params)
  const response = await fetch(url, {
    method: "POST",
    body: new XMLSerializer().serializeToString(featureRequest),
  })
  const json = await response.json()
  const features = new GeoJSON().readFeatures(json)
  const featureSet = []
  features.forEach((feature) => {
    let geom = feature.getGeometry().transform("EPSG:4326", "EPSG:3857")
    let fea = new Feature(geom)
    fea.setProperties(feature.getProperties())
    featureSet.push(fea)
  })
  this.vectorLayer.getSource().addFeatures(featureSet)
  // console.log(features);
  return json
}